﻿// ECSS JavaScript Document
var pageHeader,pageMain,pageSider,pagePanel,pageFooter,tabWrap,panelWrap,siderWrap;

function getEle(){
	pageHeader = document.getElementById("PageHeader");
	pageMain = document.getElementById("PageMain");
	pageFooter = document.getElementById("PageFooter");
	pageSider = document.getElementById("PageSider");
	pagePanel = document.getElementById("PagePanel");

	tabWrap = document.getElementById("tab_wrap");
	panelWrap = document.getElementById("panel_wrap");
	siderWrap= document.getElementById("sider_wrap");
}

function fixLayout(){
	pageMain.style.display = "none";
	var height = document.body.offsetHeight - pageHeader.offsetHeight - pageFooter.offsetHeight;
	pageMain.style.height = height -10 + "px";
	pageMain.style.display = "";
	siderWrap.style.height = panelWrap.style.height = height - 36 + "px";
	
	//adjustTab();
}

var setView={
	"panelView":function(){
		pageHeader.style.display="none";
		pageFooter.style.display="none";
		pageSider.style.display="none";
		pagePanel.style.marginLeft="0";
		fixLayout();
	},
	"liteView":function(){
		pageHeader.style.display="none";
		pageFooter.style.display="none";
		pageSider.style.display="";
		pagePanel.style.marginLeft="";
		fixLayout();
	},
	"fullView":function(){
		pageHeader.style.display="";
		pageFooter.style.display="";
		pageSider.style.display="";
		pagePanel.style.marginLeft="";
		fixLayout();
	}
}

var tab_s,panel_s;
function openTab(id,url,btnObj){
	window.frames["main_frame"].location.href=url
	//alert (111);
}
/*
function openTab(id,url,btnObj){
	if(document.getElementById(id)){
		activateTab(id);
	}else{
		try{
			tab_s.removeClass("tab_s");
			panel_s.removeClass("panel_s");
		}catch(e){}
		var txt = btnObj.innerText;
		tab_s = $("<span class='tab tab_s' id='"+id+"' title="+txt+" onclick=\"activateTab('"+id+"')\"><em>"+txt+"</em><a class='tab_close' title='关闭此标签页' onclick=\"closeTab('"+id+"')\"></a></span>");
		$(tabWrap).append(tab_s);
		panel_s = $("<iframe class='panel panel_s' id='"+id+"_panel' frameborder='0' src='"+url+"'></iframe>")
		$(panelWrap).append(panel_s);
		
		if(tabWrap.scrollWidth>=tabWrap.offsetWidth)adjustTab();
	}
}
*/

function activateTab(id){
	try{
		tab_s.removeClass("tab_s");
		panel_s.removeClass("panel_s");
	}catch(e){}
	tab_s = $("#"+id).addClass("tab_s");
	panel_s = $("#"+id+"_panel").addClass("panel_s");
}
function closeTab(id){
	if(id==tab_s.attr("id"))activateTab(tabWrap.childNodes[0].id);
	$("#"+id).remove();
	$("#"+id+"_panel").remove();
	
	if(tabWrap.scrollWidth>=tabWrap.offsetWidth-3)adjustTab();
}

function adjustTab(){
	var width = parseInt(tabWrap.offsetWidth/tabWrap.childNodes.length-2);
	if(width>=100) width=100;
	$("#adjustTabCss").html("<style type='text/css'>.tab_wrap .tab{width:"+width+"px;}</style>");
}

var tabWrapStat = 0;
function showAllTab(){
	if(tabWrapStat==0){
		tabWrap.className="tab_wrap tab_wrap_show";
		tabWrapStat = 1;
	}else{
		tabWrap.className="tab_wrap";
		tabWrapStat = 0;
		adjustTab();
	}
}

function initList(){
	$("h4",siderWrap).click(function(){
		$(this).next("p").slideToggle("fast").parent().toggleClass("list_act");
	});
}

$(document).ready(function(){
	getEle();
	fixLayout();
	initList();
});

window.onresize = function(){
	fixLayout();
} 
